package com.example.administrator.yuejian_15.activity;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.administrator.yuejian_15.R;
import com.example.administrator.yuejian_15.bean.SuccessBean;
import com.example.administrator.yuejian_15.listener.TListener;
import com.example.administrator.yuejian_15.model.SetPasswordModel;


public class SetPasswordActivity extends BaseActivity implements View.OnClickListener {

    ImageView szmm_fh;
    EditText szmm_password,szmm_password1;
    Button szmm_botton;

    @Override
    void initView() {
        setLayout_file(R.layout.activity_set_password);
        szmm_fh=(ImageView)findViewById(R.id.szmm_fh);
        szmm_password=(EditText)findViewById(R.id.szmm_password);
        szmm_password1=(EditText)findViewById(R.id.szmm_password1);
        szmm_botton=(Button)findViewById(R.id.szmm_botton);
    }

    @Override
    void initEvent() {
        szmm_fh.setOnClickListener(this);
        szmm_botton.setOnClickListener(this);

    }

    @Override
    void initDate() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.szmm_fh:
                finish();
                break;
            case R.id.szmm_botton:
                String password = szmm_password.getText().toString().trim();
                String password1 = szmm_password1.getText().toString().trim();
                String uid=getid();
                if (password.equals("") || password1.equals("")) {
                    Toast.makeText(SetPasswordActivity.this,"密码不能为空",Toast.LENGTH_SHORT).show();
                }
                else if (!password.equals(password1)){
                    Toast.makeText(SetPasswordActivity.this,"两次密码不一致",Toast.LENGTH_SHORT).show();
                }
                else{
                    SetPasswordModel setPasswordModel = new SetPasswordModel();
                    setPasswordModel.setPassword(uid,password,successBeanTListener);
                }
        }
    }
    TListener<SuccessBean> successBeanTListener=new TListener<SuccessBean>() {
        @Override
        public void onResponse(SuccessBean successBean) {
            String success = successBean.getSuccess();
            if (success.equals("1")){
                Toast.makeText(SetPasswordActivity.this,"修改成功",Toast.LENGTH_SHORT).show();
                finish();
            }
            else{
                Toast.makeText(SetPasswordActivity.this,"修改失败",Toast.LENGTH_SHORT).show();
            }

        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(SetPasswordActivity.this,"修改失败，或网络错误",Toast.LENGTH_SHORT).show();

        }
    };

}
